//backround与 content的区别在哪

// 不能直接访问dom, 访问chrome 拓展api 常用于content通信
//算是一个通信中间层吧, 中转站

// V2旧版本才能使用
console.log(chrome, "backgournd执行")

chrome.webRequest.onBeforeSendHeaders.addListener(
  function (details) {
    console.log(details, "cookie")

    // 修改请求header
    details.requestHeaders.push({
      name: "Custom-Header",
      value: "Custom Value"
    })

    // 修改cookie
    details.requestHeaders.push({
      name: "Cookie",
      value: "cookie1=abc; cookie2=def"
    })

    return { requestHeaders: details.requestHeaders }
  },
  { urls: ["<all_urls>"] },
  ["requestHeaders", "blocking"]
)

chrome.webRequest.onBeforeRequest.addListener(
  function (details) {
    console.log(details, "request")

    // 修改重定向URL
    return { redirectUrl: "https://example.com/redirected-url" }
  },
  { urls: ["<all_urls>"] },
  ["blocking"]
)
